Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml
Imports OpenArchive.Document.Components.Data

Namespace OpenArchive
    Namespace Document
        Namespace Components
            Public MustInherit Class Component
                Implements IComponent

                Private m_ComponentData As Data.IComponentData
                Private WithDigitalSignature As Boolean
                Private m_ComponentName As String
                Friend Event ReadRequested(ByVal sender As IComponent) Implements IComponent.ReadRequested
                Protected Property Version() As Version
                    Get
                        Return DataObjects.Version
                    End Get
                    Set(ByVal value As Version)
                        DataObjects.Version = value
                    End Set
                End Property
                Friend Property DataObjects() As Data.IComponentData Implements IComponent.DataObjects
                    Get
                        If m_ComponentData Is Nothing Then
                            ' Read Data

                            RaiseEvent ReadRequested(Me)
                        End If
                        Return m_ComponentData
                    End Get
                    Set(ByVal value As Data.IComponentData)
                        m_ComponentData = value
                    End Set
                End Property
                Protected ReadOnly Property DigitalSignature() As Byte()
                    Get
                        Return m_ComponentData.DigitalSignature.ToBinary
                    End Get
                End Property
                Protected Function VerifySignature() As Boolean
                    ' Test if the content match the signature
                End Function
                Protected Property Content() As Object Implements IComponent.Content
                    Get
                        Return m_ComponentData.Content
                    End Get

                    Set(ByVal value As Object)
                        If WithDigitalSignature Then
                            ' generate and set digitale Signature
                            'LoadSignaturProvider
                        End If
                        m_ComponentData.Content = value
                    End Set
                End Property

                Public ReadOnly Property ComponentName() As String Implements IComponent.ComponentName
                    Get
                        'Return System.Resources.ResourceManager() or localisation service
                    End Get
                End Property
                Protected Sub SetComponentName(ByVal compname As String)
                    m_ComponentName = compname
                End Sub
                Friend MustOverride Function IsResponsible(ByVal ComponentDataType As Global.System.Type, ByVal Version As Version) As Object Implements IComponent.IsResponsible
                MustOverride ReadOnly Property IsSingleInstanceType() As Boolean Implements IComponent.IsSingleInstanceType
            End Class
        End Namespace
    End Namespace
End Namespace